package com.hzhr.iot.collect.service.helper;

import com.hzhr.iot.collect.Global;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.sdk.model.alarmData.AlarmDataPostModel;
import com.hzhr.iot.device.sdk.service.Device_AlarmDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Component
public class Device_AlarmDataServiceHelper {
    @Autowired
    Device_AlarmDataService device_alarmDataService;
    @Autowired
    Global global;

    public void post(AlarmDataPostModel model) throws ServiceException {
        Map<String, Object> query = new HashMap<>();
        device_alarmDataService.post(global.initGlobalHeader(), query, model);
    }

    public int getCountByIotDeviceIdAndCurrentTm(int iotDeviceId, Date currentTm) throws ServiceException {
        Map<String, Object> query = new HashMap<>();
        query.put("_show_total", true);
        query.put("_equal_iotDeviceId", iotDeviceId);
        query.put("_equal_currentTm", currentTm.getTime());
        int total = device_alarmDataService.get(global.initGlobalHeader(), query).getTotal();
        return total;
    }

}
